
var maxArea = function (height) {
    max = new Number(0);
    i = new Number(0);
    j = height.length-1;
    
    while (i < j) {
        tmp = cal(i, j, height[i], height[j]);
        if (height[i] > height[j]) {
            j--;
        } else {
            i++;
        }
        if (tmp > max) {
            max = tmp;
        }
    }
    return max;
};

function cal(i, j, hi, hj) {
    sm = new Number(0);
    if (hi > hj) {
        sm = hj;
    } else {
        sm = hi;
    }
    return sm * (j - i);
}
console.log(maxArea([3, 2, 1, 4]))
